package com.ruoyi.web.domain.device;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.time.LocalDateTime;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.web.utils.v2.V2DeviceInfo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 设备管理
 *
 * @author fwx
 * @since 2024-01-08 16:03:56
 */
@Data
@TableName("tt_device_info")
@ApiModel(value = "DeviceInfo对象", description = "设备管理")
public class DeviceInfo implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @ApiModelProperty("设备类型")
    @TableField("device_type")
    private String deviceType;

    @ApiModelProperty("产品id")
    @TableField("product_id")
    private Long productId;

    @ApiModelProperty("设备id")
    @TableField("device_id")
    private String deviceId;

    @ApiModelProperty("用户id")
    @TableField("user_id")
    private Long userId;

    @ApiModelProperty("用户名")
    @TableField("username")
    private String username;

    @ApiModelProperty("绑定时间")
    @TableField("bind_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime bindTime;

    @ApiModelProperty(value = "在线状态: offline:离线, online:在线, fault:故障 ,nothing:无")
    private String lineState;

    @ApiModelProperty(value = "设备名称")
    private String deviceName;

    @TableField(exist = false)
    private String address;

    @ApiModelProperty(value = "产品名称")
    @TableField(exist = false)
    private String productName;

    @ApiModelProperty(value = "产品类型")
    @TableField(exist = false)
    private String typeName;

    @TableField(exist = false)
    private String photo;

    @ApiModelProperty(value = "经度")
    @TableField(exist = false)
    private String lon;
    @ApiModelProperty(value = "纬度")
    @TableField(exist = false)
    private String lat;

    public DeviceInfo() {
    }

    public DeviceInfo(String deviceId, String deviceType) {
        this.deviceId = deviceId;
        this.deviceType = deviceType;
    }

    /**
     * @desc  绑定设备其他属性
     * @author fwx 2024/1/9 17:41
     **/
    public void buildOther(V2DeviceInfo v2){
        if(v2 == null){
            return;
        }

        this.address = v2.getAddress();
        this.deviceName = v2.getName();
        this.productName = v2.getProductName();
        this.lineState = v2.getState() != null ? v2.getState()  : "nothing";
        this.lat = v2.getLat();
        this.lon = v2.getLon();
        this.typeName = v2.getTypeName();
        this.photo = v2.getPhoto();
        this.productId = v2.getProductId();
    }

}
